/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.fraction;

import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.Component;
import ohos.app.Context;

import com.xuexiang.xui_lib.component.GridLayout;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.ability.AssemblySearchAbility;
import com.xuexiang.xuidemo.ability.ButtonAbility;
import com.xuexiang.xuidemo.ability.DialogAbility;
import com.xuexiang.xuidemo.ability.DropdownboxAbility;
import com.xuexiang.xuidemo.ability.EditTextAbiliy;
import com.xuexiang.xuidemo.ability.FlowLayoutAbility;
import com.xuexiang.xuidemo.ability.GuideViewAbility;
import com.xuexiang.xuidemo.ability.ImageAbility;
import com.xuexiang.xuidemo.ability.MarqueenAbility;
import com.xuexiang.xuidemo.ability.PickerAbility;
import com.xuexiang.xuidemo.ability.PopupWindowAbility;
import com.xuexiang.xuidemo.ability.ProgressBarAbility;
import com.xuexiang.xuidemo.ability.RefreshLayoutAbility;
import com.xuexiang.xuidemo.ability.StatusLayoutAbility;
import com.xuexiang.xuidemo.ability.TabBarAbility;
import com.xuexiang.xuidemo.ability.TitleBarAbility;
import com.xuexiang.xuidemo.ability.XUILayoutAbility;
import com.xuexiang.xuidemo.factory.AdapterFactory;
import com.xuexiang.xuidemo.fractionstacklayout.BaseFraction;
import com.xuexiang.xuidemo.page.text.TextAbility;
import com.xuexiang.xuidemo.slice.banner.BannerAbility;
import com.xuexiang.xuidemo.util.JumpUtil;

/**
 * 组件
 *
 * @since 2021-03-30
 */
public class AssemblyFraction extends BaseFraction implements GridLayout.OnItemClickListener {
    private Context context;
    private final int anInt1 = 1;
    private final int anInt2 = 2;
    private final int anInt3 = 3;
    private final int anInt4 = 4;
    private final int anInt5 = 5;
    private final int anInt6 = 6;
    private final int anInt7 = 7;
    private final int anInt8 = 8;
    private final int anInt9 = 9;
    private final int anInt10 = 10;
    private final int anInt11 = 11;
    private final int anInt12 = 12;
    private final int anInt13 = 13;
    private final int anInt14 = 14;
    private final int anInt15 = 15;
    private final int anInt16 = 16;
    private final int anInt17 = 17;
    private final int anInt18 = 18;

    @Override
    public int getUicontent() {
        return ResourceTable.Layout_fraction_assembly;
    }

    @Override
    public void initComponent() {
        context = mComponent.getContext();
        GridLayout gridLayout = (GridLayout) mComponent.findComponentById(ResourceTable.Id_grid_layout);
        gridLayout.setSpanCount(anInt3);
        gridLayout.setSpacing(AttrHelper.vp2px(anInt2, context));
        gridLayout.setOnItemClickListener(this);
        gridLayout.setProvider(AdapterFactory.getInstance().getAssemblyAdapter(context));
    }

    @Override
    public void onItemClick(Component component, int position) {
        switch (position) {
            case 0:
                JumpUtil.jumpToAbility(mComponent.getContext(), BannerAbility.class);
                break;
            case anInt1:
                JumpUtil.jumpToAbility(mComponent.getContext(), ButtonAbility.class);
                break;
            case anInt2:
                JumpUtil.jumpToAbility(mComponent.getContext(), DialogAbility.class);
                break;
            case anInt3:
                /*Intent secondIntent = new Intent(); // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.xuexiang.xuidemo")
                    .withAbilityName("com.xuexiang.xuidemo.ability.EditTextAbiliy")
                    .build();
                secondIntent.setOperation(operation); // 通过AbilitySlice的startAbility接口实现启动另一个页面
                context.startAbility(secondIntent, 0);*/
                JumpUtil.jumpToAbility(mComponent.getContext(), EditTextAbiliy.class);
                break;
            case anInt4:
                JumpUtil.jumpToAbility(mComponent.getContext(), FlowLayoutAbility.class);
                break;

            case anInt5:
                JumpUtil.jumpToAbility(mComponent.getContext(), GuideViewAbility.class);
                break;
            case anInt6:
                JumpUtil.jumpToAbility(mComponent.getContext(), ImageAbility.class);
                break;
            case anInt7: // 通用布局
                JumpUtil.jumpToAbility(mComponent.getContext(), XUILayoutAbility.class);
                break;
            case anInt8:
                JumpUtil.jumpToAbility(mComponent.getContext(), MarqueenAbility.class);
                break;
            case anInt9:
                JumpUtil.jumpToAbility(mComponent.getContext(), PickerAbility.class);
                break;
            case anInt10:
                JumpUtil.jumpToAbility(mComponent.getContext(), PopupWindowAbility.class);
                break;
            case anInt12:
                JumpUtil.jumpToAbility(mComponent.getContext(), RefreshLayoutAbility.class);
                break;
            case anInt13: // 主页搜索框
                JumpUtil.jumpToAbility(mComponent.getContext(), AssemblySearchAbility.class);
                break;
            case anInt14: // 导航栏
                JumpUtil.jumpToAbility(mComponent.getContext(), DropdownboxAbility.class);
                break;
            case anInt11:
                JumpUtil.jumpToAbility(mComponent.getContext(), ProgressBarAbility.class);
                break;
            case anInt15:
                JumpUtil.jumpToAbility(mComponent.getContext(), StatusLayoutAbility.class);
                break;
            case anInt16:
                JumpUtil.jumpToAbility(mComponent.getContext(), TabBarAbility.class);
                break;
            case anInt17: // 文字
                JumpUtil.jumpToAbility(mComponent.getContext(), TextAbility.class);
                break;
            case anInt18:
                JumpUtil.jumpToAbility(mComponent.getContext(), TitleBarAbility.class);
                break;
            default:
                break;
        }
    }
}
